import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/ls")
public class Loginsevlet extends HttpServlet
{private static final long serialVersionUID=1L;
  public Loginsevlet(){
    super();
  }

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doPost(req, resp);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    req.setCharacterEncoding("utf-8");
    String user=req.getParameter("user");
    RequestDispatcher rd=null;
    if(user!=null&&user.equals("admin")){
      req.getSession().setAttribute("login","true");
      rd=req.getRequestDispatcher("/admin.html");
      rd.forward(req,resp);
    }
    else if(user!=null&&user.equals("common")){
      req.getSession().setAttribute("login","true");
      rd=req.getRequestDispatcher("/common.html");
      rd.forward(req,resp);
    }
    else if (user!=null) {
      req.getSession().setAttribute("login","true");
      rd=req.getRequestDispatcher("/user.jsp");
      rd.forward(req,resp);
    }
      else{
        resp.sendRedirect("login.html");
      }
    }
  }

